package com.baway.biliclitent;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.baway.biliclitent.fragment.FragmentMain;

public class MainActivity extends AppCompatActivity {
    private DrawerLayout mDrawerLayout;
    private SwipeRefreshLayout swipeRefreshLayout;
    private NavigationView navView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //获取id  侧滑
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        //侧滑布局
        navView = (NavigationView) findViewById(R.id.nav_view);
        //添加一个Fragmet
        FragmentManager manager = getSupportFragmentManager();
        manager.beginTransaction().add(R.id.frament,new FragmentMain()).commit();
        navView.setCheckedItem(R.id.item_home);
        navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                //关闭侧滑
                mDrawerLayout.closeDrawers();
                return true;
            }
        });
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //显示菜单需这行代码
        getMenuInflater().inflate(R.menu.toolbar,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.backup:
                Toast.makeText(this, "backup", Toast.LENGTH_SHORT).show();
                break;
            case R.id.delete:
                Toast.makeText(this, "delete", Toast.LENGTH_SHORT).show();
                break;
            case R.id.settings:
                Toast.makeText(this, "settings", Toast.LENGTH_SHORT).show();
                break;
            //HomeAsUp按钮的id永远是这个
            case R.id.item_home:
                Toast.makeText(this, "碰我", Toast.LENGTH_SHORT).show();
            break;
            case android.R.id.home:
                //打开侧滑菜单，并设置打开模式
                mDrawerLayout.openDrawer(GravityCompat.START);
                break;
        }
        return true;
    }
}
